<?php
/**
 * Created by PhpStorm.
 * User: Raytine
 * Date: 2018/8/30
 * Time: 11:55
 */

namespace PddWechat\Models\User\Dao;

use Dai\Framework\Base\BaseDao;
use Dai\Framework\Library\Log;
use PddWechat\Models\User\DataObject\UserBankCardDo;

/**
 * Class UserDao
 * @dataObject(\PddWechat\Models\User\DataObject\UserBankCardDo)
 * @package PddWechat\Models\User\Dao
 */
class BindBankCardDao extends BaseDao
{
    public function insert(UserBankCardDo $userBankCardDo) {
        $userBankCardDo->id = $this->execute("user.user_bank_card.insert", $userBankCardDo);
        return $userBankCardDo;
    }

    public function edit( UserBankCardDo $userBankCardDo, $where=null){
        if( trim($where) == "" && intval($userBankCardDo->id) <= 0) {
            Log::error("update where or id must exist");
            return false;
        }
        $sql = "UPDATE jd.user_bank_card SET bankCard = '" . strval($userBankCardDo->bankCard) . "',userName = '" .
            strval($userBankCardDo->userName) . "', updateTime = '" . date('Y-m-d H:i:s') . "',phone = '".strval($userBankCardDo->phone) ."' WHERE uid = " .
            intval($userBankCardDo->uid);
        $res = $this->execRaw($sql);
        if($res) {
            return $userBankCardDo;
        }
        return false;
    }

    public function selectByUid($uid) {
        $param = [
            'uid' => $uid,
            'select' => "*",
        ];
        $res = $this->execute("user.user_bank_card.select_by_uid", $param);
        if( count($res) > 0 ){
            return $this->trimBase($res[0]);
        }else {
            return null;
        }
    }

}